package com.cj.service.impl;


import com.cj.dao.DormitoryDao;
import com.cj.po.PageInfo;
import com.cj.po.Dormitory;
import com.cj.service.DormitoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 用户Service接口实现类
 */
@Service("dormitoryService")
@Transactional
public class DormitoryServiceImpl implements DormitoryService {
    // 注入studentDao
    @Autowired
    private DormitoryDao dormitoryDao;


    //分页查询
    @Override
    public PageInfo<Dormitory> findPageInfo(Integer s_dormitoryid, String d_dormbuilding, String d_bedtotal, String d_bed,String a_name, Integer pageIndex, Integer pageSize) {
        PageInfo<Dormitory> pi = new PageInfo<Dormitory>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = dormitoryDao.totalCount(s_dormitoryid, d_dormbuilding, a_name);
        if (totalCount > 0) {
            pi.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Dormitory> dormitoryList = dormitoryDao.getDormitoryList(s_dormitoryid, d_dormbuilding, a_name,
                    (pi.getPageIndex() - 1) * pi.getPageSize(), pi.getPageSize());
            pi.setList(dormitoryList);
        }
        return pi;
    }

    @Override
    public List<Dormitory> getAll(){
        List<Dormitory> dormitoryList= dormitoryDao.getAll();
        return dormitoryList;
    }

    @Override
    public int deleteDormitory(Integer d_id) {
        return dormitoryDao.deleteDormitory(d_id);
    }


    @Override
    public int addDormitory(Dormitory dormitory) {
        return dormitoryDao.addDormitory(dormitory);
    }

    @Override
    public int updateDormitory(Dormitory dormitory) {
        return dormitoryDao.updateDormitory(dormitory);
    }

    @Override
    public Dormitory findDormitoryById(Integer d_id) {
        return dormitoryDao.findDormitoryById(d_id);
    }


}
